var app = getApp() 
var pageObject = {
  data: {
    doctor: {}, 
    indicatorDots: true,
    countdown: 60, 
    autoplay: true,
    interval: 5000,
    duration: 400,
    modalState: false,  
    hiddenmodalput: true,
  },
  onLoad: function(options) { 
    this.getDoctorInfo(options);
  },
  buyBtnEvent: function(event) {
    var loginUserId = wx.getStorageSync('LOGINUSER_ID') || '';
    wx.request({ 
      url: app.globalData.buy_buy_url,
      data: {userId:loginUserId,productId:event.currentTarget.dataset.id,name:event.currentTarget.dataset.name,nums:1,finish:1,price:event.currentTarget.dataset.price,name:event.currentTarget.dataset.name,factory:event.currentTarget.dataset.factory},
      method: 'POST', 
      success: function (res) {
        var resultData = res.data;
        if(resultData.errno == 0){
           app.showModel("购买结果",resultData.message);
        }
      },
      fail: function () {
        setTimeout(function () {
          wx.showToast({
            title: "加载失败"
          })
        }, 100)
      }
    })
  },
  cancel: function () {
    this.setData({ 
       hiddenmodalput: true 
    });
  },
  bindTextAreaBlur:function(event){ 
    this.setData({
       content: event.detail.value,
    })
  },
  countDownEvent: function() {
    var _this = this
    var sendPhoneCodeInterval = setInterval(function() {
      if (_this.data.countdown == 0) {
        clearInterval(sendPhoneCodeInterval)
        _this.setData({
          countdown: 60,
          hasSend: false
        })
      } else {
        _this.setData({
          countdown: _this.data.countdown - 1
        })
      }
    }, 1000)
  }, 
  getDoctorInfo: function(options) {
    var _this = this; 
    wx.request({ 
      url: app.globalData.doctor_detail_url,
      data: {
        id : options.id
      },
      method: 'GET', 
      success: function (res) {
        var resultData = res.data;
        if(resultData.errno==0){ 
          _this.setData({ 
            doctor:resultData.data,
          })
        }
      },
      fail: function () {
        setTimeout(function () {
          wx.showToast({
            title: "加载失败"
          })
        }, 100)
      }
    }) 
  },  
  guahao: function(event) { 
    var loginUserId = wx.getStorageSync('LOGINUSER_ID') || '';
    if(loginUserId == ''){
      wx.redirectTo({
        url: '../index/index'
      })
    }else{
      wx.request({ 
        url: app.globalData.appointment_add_url,
        data: {userId:loginUserId,doctorId:event.currentTarget.dataset.id },
        method: 'POST', 
        success: function (res) {
          var resultData = res.data;
          if(resultData.errno == 0){
             app.showModel("预约结果",resultData.message)
          }
        },
        fail: function () {
          setTimeout(function () {
            wx.showToast({
              title: "加载失败"
            })
          }, 100)
        }
      })
    } 
  }, 
  liuyan:function(event) {  
    var loginUserId = wx.getStorageSync('LOGINUSER_ID') || '';
    if(loginUserId == ''){
      wx.redirectTo({
        url: '../index/index'
      })
    }else{
      this.setData({ 
        hiddenmodalput: !this.data.hiddenmodalput,
        doctorId: event.currentTarget.dataset.id,
        content: '',
        }) 
    }
  },
  confirm: function () {
    var _this = this;
    var loginUserId = wx.getStorageSync('LOGINUSER_ID') || '';
    if(''== _this.data.content){
        app.showLoading("输入框不能为空")
      return 
    } 
    wx.request({ 
      url: app.globalData.message_add_url,
      data: {userId:loginUserId,doctorId:_this.data.doctorId,content:_this.data.content },
      method: 'POST', 
      success: function (res) {
        var resultData = res.data;
        if(resultData.errno == 0){
           app.showModel("留言结果",resultData.message)
           _this.setData({
            hiddenmodalput: true
          })
        }
      },
      fail: function () {
        setTimeout(function () {
          wx.showToast({
            title: "加载失败"
          })
        }, 100)
      }
    }) 
  },
}

Page(pageObject)
